<template>
	<div class="activeTabs">
		<h3>Tabs 标签页</h3>
		<div class="tabs1">
			<h4>基础用法</h4>
			<el-tabs v-model="activeName" @tab-click="handleClick">
				<el-tab-pane label="用户管理" name="first">用户管理</el-tab-pane>
				<el-tab-pane label="配置管理" name="second">配置管理</el-tab-pane>
				<el-tab-pane label="角色管理" name="third">角色管理</el-tab-pane>
				<el-tab-pane label="定时任务补偿" name="fourth">定时任务补偿</el-tab-pane>
			</el-tabs>
		</div>

		<div class="tabs2">
			<h4>选项卡样式</h4>
			<el-tabs v-model="activeName2" type="card" @tab-click="handleClick">
				<el-tab-pane label="用户管理" name="first">用户管理</el-tab-pane>
				<el-tab-pane label="配置管理" name="second">配置管理</el-tab-pane>
				<el-tab-pane label="角色管理" name="third">角色管理</el-tab-pane>
				<el-tab-pane label="权限管理" name="fourth">权限管理</el-tab-pane>
			</el-tabs>
		</div>

		<div class="tabs3">
			<h4>卡片化</h4>
			<el-tabs v-model="activeName3" type="border-card" @tab-click="handleClick">
				<el-tab-pane label="用户管理" name="first">用户管理</el-tab-pane>
				<el-tab-pane label="配置管理" name="second">配置管理</el-tab-pane>
				<el-tab-pane label="角色管理" name="third">角色管理</el-tab-pane>
				<el-tab-pane label="权限管理" name="fourth">权限管理</el-tab-pane>
			</el-tabs>
		</div>

		<div class="tabs4">
			<h4>位置</h4>
			<el-radio-group v-model="tabPosition" style="margin-bottom: 30px;">
				<el-radio-button label="top">top</el-radio-button>
				<el-radio-button label="right">right</el-radio-button>
				<el-radio-button label="left">left</el-radio-button>
				<el-radio-button label="bottom">bottom</el-radio-button>
			</el-radio-group>
			<el-tabs :tab-position="tabPosition" style="height: 200px;">
				<el-tab-pane label="用户管理" name="first">用户管理</el-tab-pane>
				<el-tab-pane label="配置管理" name="second">配置管理</el-tab-pane>
				<el-tab-pane label="角色管理" name="third">角色管理</el-tab-pane>
				<el-tab-pane label="权限管理" name="fourth">权限管理</el-tab-pane>
			</el-tabs>
		</div>

		<div class="tabs5">
			<h4>自定义标签页</h4>
			<el-tabs type="border-card">
				<el-tab-pane>
					<span slot="label"><i class="el-icon-date"></i> 我的行程</span> 我的行程
				</el-tab-pane>
				<el-tab-pane label="消息中心">消息中心</el-tab-pane>
				<el-tab-pane label="角色管理">角色管理</el-tab-pane>
				<el-tab-pane label="定时任务补偿">定时任务补偿</el-tab-pane>
			</el-tabs>
		</div>

		<div class="tabs6">
			<h4>动态增减标签页</h4>
			<el-tabs v-model="editableTabsValue" type="card" editable @edit="handleTabsEdit">
				<el-tab-pane v-for="(item,index) in editableTabs" :key="item.name" :label="item.title" :name="item.name">
					{{item.pane}}
				</el-tab-pane>
			</el-tabs>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				activeName: 'second',
				activeName2: 'third',
				activeName3: 'first',
				tabPosition: 'top',
				editableTabsValue: '2',
				editableTabs: [{
					title: 'Tab 1',
					name: '1',
					content: 'Tab 1 content'
				}, {
					title: 'Tab 2',
					name: '2',
					content: 'Tab 2 content'
				}],
				tabIndex: 2
			}
		},
		methods: {
			handleClick(tab, event) {
				console.log(tab, event);
			},
			handleTabsEdit(targetName, action) {
				if(action == 'add') {
					let newTabName = ++this.tabIndex + '';
					this.editableTabs.push({
						title: 'New Tab',
						name: newTabName,
						content: 'New Tab content'
					});
					this.editableTabsValue = newTabName;
				}

				if(action == 'remove') {
					let tabs = this.editableTabs;
					let activeName = this.editableTabsValue;

					if(activeName === targetName) {
						tabs.forEach((tab, index) => {
							if(tab.name === targetName) {
								let nextTab = tabs[index + 1] || tabs[index - 1];
								if(nextTab) {
									activeName = nextTab.name;
								}
							}
						});
					}

					this.editableTabsValue = activeName;
					this.editableTabs = tabs.filter(tab => tab.name !== targetName);

				}
			}
		}
	}
</script>

<style>

</style>